/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.unice.miage.m2.webservices.cl.xbay.model;

import java.io.Serializable;
import fr.unice.miage.m2.webservices.cl.xbay.tools.Tools;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class ThirdPartyProduct implements Serializable {

    private static final long serialVersionUID = 1L;
    private String id;
    private String tags;
    private String name;
    private String descr;
    private Float price;
  
 
    private String[] images;

    public ThirdPartyProduct() {
        images = new String[0];
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String[] getImages() {
        return images;
    }

    public void setImages(String[] images) {
        this.images = images;
    }

    
   

    public String getTags() {
        return tags;
    }

    public void setTags(String tags) {
        this.tags = tags;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescr() {
        return descr;
    }

    public void setDescr(String descr) {
        this.descr = descr;
    }

    public Float getPrice() {
        return price;
    }

    public void setPrice(Float price) {
        this.price = price;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ThirdPartyProduct)) {
            return false;
        }
        ThirdPartyProduct other = (ThirdPartyProduct) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        StringBuilder b = new StringBuilder();
        b.append(this.id);
        b.append(", ");
        b.append(this.name);
        b.append(", ");
        b.append(this.descr);
        b.append(", ");
        b.append(this.tags);
        b.append(", ");
        b.append(this.price);
        b.append(", ");
        for (String s : images) {
            b.append(s);
        }
        return b.toString();
    }

    public Product toProduct() {
        Product p = new Product();
        p.setName(name);
        p.setDescr(descr);
        p.setTags(tags);
        p.setStock(0);
        p.setPrice(price);
        // FIXME
        String imgPath = Tools.captureUrlImage("/product_images", "product_" + id, p.getImgBig());
        p.setImgBig(imgPath);

        return p;
    }
}
